home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Online / Apache / include / php / Zend / zend_execute.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-12-05  |  5.7 KB  |  214 lines

  1. /*
  2.    +----------------------------------------------------------------------+
  3.    | Zend Engine                                                          |
  4.    +----------------------------------------------------------------------+
  5.    | Copyright (c) 1998-2000 Zend Technologies Ltd. (http://www.zend.com) |
  6.    +----------------------------------------------------------------------+
  7.    | This source file is subject to version 0.92 of the Zend license,     |
  8.    | that is bundled with this package in the file LICENSE, and is        | 
  9.    | available at through the world-wide-web at                           |
  10.    | http://www.zend.com/license/0_92.txt.                                |
  11.    | If you did not receive a copy of the Zend license and are unable to  |
  12.    | obtain it through the world-wide-web, please send a note to          |
  13.    | license@zend.com so we can mail you a copy immediately.              |
  14.    +----------------------------------------------------------------------+
  15.    | Authors: Andi Gutmans <andi@zend.com>                                |
  16.    |          Zeev Suraski <zeev@zend.com>                                |
  17.    +----------------------------------------------------------------------+
  18. */
  19.  
  20.  
  21. #ifndef ZEND_EXECUTE_H
  22. #define ZEND_EXECUTE_H
  23.  
  24. #include "zend_compile.h"
  25. #include "zend_hash.h"
  26. #include "zend_variables.h"
  27. #include "zend_execute_locks.h"
  28.  
  29. typedef union _temp_variable {
  30.     zval tmp_var;
  31.     struct {
  32.         zval **ptr_ptr;
  33.         zval *ptr;
  34.     } var;
  35.     struct {
  36.         zval tmp_var; /* a dummy */
  37.  
  38.         union {
  39.             struct {
  40.                 zval *str;
  41.                 int offset;
  42.             } str_offset;
  43.             zend_property_reference overloaded_element;
  44.         } data;
  45.             
  46.         unsigned char type;
  47.     } EA;
  48. } temp_variable;
  49.  
  50.  
  51. ZEND_API extern void (*zend_execute)(zend_op_array *op_array ELS_DC);
  52.  
  53. void init_executor(CLS_D ELS_DC);
  54. void shutdown_executor(ELS_D);
  55. void execute(zend_op_array *op_array ELS_DC);
  56. ZEND_API int zend_is_true(zval *op);
  57. static inline void safe_free_zval_ptr(zval *p)
  58. {
  59.     ELS_FETCH();
  60.  
  61.     if (p!=EG(uninitialized_zval_ptr)) {
  62.         FREE_ZVAL(p);
  63.     }
  64. }
  65.  
  66. ZEND_API int zend_eval_string(char *str, zval *retval_ptr, char *string_name CLS_DC ELS_DC);
  67. static inline int i_zend_is_true(zval *op)
  68. {
  69.     int result;
  70.  
  71.     switch (op->type) {
  72.         case IS_NULL:
  73.             result = 0;
  74.             break;
  75.         case IS_LONG:
  76.         case IS_BOOL:
  77.         case IS_RESOURCE:
  78.             result = (op->value.lval?1:0);
  79.             break;
  80.         case IS_DOUBLE:
  81.             result = (op->value.dval ? 1 : 0);
  82.             break;
  83.         case IS_STRING:
  84.             if (op->value.str.len == 0
  85.                 || (op->value.str.len==1 && op->value.str.val[0]=='0')) {
  86.                 result = 0;
  87.             } else {
  88.                 result = 1;
  89.             }
  90.             break;
  91.         case IS_ARRAY:
  92.             result = (zend_hash_num_elements(op->value.ht)?1:0);
  93.             break;
  94.         case IS_OBJECT:
  95.             result = (zend_hash_num_elements(op->value.obj.properties)?1:0);
  96.             break;
  97.         default:
  98.             result = 0;
  99.             break;
  100.     }
  101.     return result;
  102. }
  103.  
  104. ZEND_API int zval_update_constant(zval **pp, void *arg);
  105.  
  106. /* dedicated Zend executor functions - do not use! */
  107. static inline void zend_ptr_stack_clear_multiple(ELS_D)
  108. {
  109.     void **p = EG(argument_stack).top_element-2;
  110.     int delete_count = (ulong) *p;
  111.  
  112.     EG(argument_stack).top -= (delete_count+2);
  113.     while (--delete_count>=0) {
  114.         zval_ptr_dtor((zval **) --p);
  115.     }
  116.     EG(argument_stack).top_element = p;
  117. }
  118.  
  119. static inline int zend_ptr_stack_get_arg(int requested_arg, void **data ELS_DC)
  120. {
  121.     void **p = EG(argument_stack).top_element-2;
  122.     int arg_count = (ulong) *p;
  123.  
  124.     if (requested_arg>arg_count) {
  125.         return FAILURE;
  126.     }
  127.     *data = (p-arg_count+requested_arg-1);
  128.     return SUCCESS;
  129. }
  130.  
  131. #if SUPPORT_INTERACTIVE
  132. void execute_new_code(CLS_D);
  133. #endif
  134.  
  135.  
  136. /* services */
  137. ZEND_API char *get_active_function_name(void);
  138. ZEND_API char *zend_get_executed_filename(ELS_D);
  139. ZEND_API uint zend_get_executed_lineno(ELS_D);
  140. ZEND_API zend_bool zend_is_executing(void);
  141.  
  142. ZEND_API void zend_set_timeout(long seconds);
  143. ZEND_API void zend_unset_timeout(void);
  144. ZEND_API void zend_timeout(int dummy);
  145.  
  146. #ifdef ZEND_WIN32
  147. void zend_init_timeout_thread();
  148. void zend_shutdown_timeout_thread();
  149. #define WM_REGISTER_ZEND_TIMEOUT        (WM_USER+1)
  150. #define WM_UNREGISTER_ZEND_TIMEOUT        (WM_USER+2)
  151. #endif
  152.  
  153. #define zendi_zval_copy_ctor(p) zval_copy_ctor(&(p))
  154. #define zendi_zval_dtor(p) zval_dtor(&(p))
  155.  
  156. #define active_opline (*EG(opline_ptr))
  157.  
  158. static inline void zend_assign_to_variable_reference(znode *result, zval **variable_ptr_ptr, zval **value_ptr_ptr, temp_variable *Ts ELS_DC)
  159. {
  160.     zval *variable_ptr;
  161.     zval *value_ptr;
  162.  
  163.     if (!value_ptr_ptr || !variable_ptr_ptr) {
  164.         zend_error(E_ERROR, "Cannot create references to/from string offsets nor overloaded objects");
  165.         return;
  166.     }
  167.  
  168.     variable_ptr = *variable_ptr_ptr;
  169.     value_ptr = *value_ptr_ptr;
  170.  
  171.     if (variable_ptr == EG(error_zval_ptr) || value_ptr==EG(error_zval_ptr)) {
  172.         variable_ptr_ptr = &EG(uninitialized_zval_ptr);
  173. /*    } else if (variable_ptr==&EG(uninitialized_zval) || variable_ptr!=value_ptr) { */
  174.     } else if (variable_ptr_ptr != value_ptr_ptr) {
  175.         variable_ptr->refcount--;
  176.         if (variable_ptr->refcount==0) {
  177.             zendi_zval_dtor(*variable_ptr);
  178.             FREE_ZVAL(variable_ptr);
  179.         }
  180.  
  181.         if (!PZVAL_IS_REF(value_ptr)) {
  182.             /* break it away */
  183.             value_ptr->refcount--;
  184.             if (value_ptr->refcount>0) {
  185.                 ALLOC_ZVAL(*value_ptr_ptr);
  186.                 **value_ptr_ptr = *value_ptr;
  187.                 value_ptr = *value_ptr_ptr;
  188.                 zendi_zval_copy_ctor(*value_ptr);
  189.             }
  190.             value_ptr->refcount = 1;
  191.             value_ptr->is_ref = 1;
  192.         }
  193.  
  194.         *variable_ptr_ptr = value_ptr;
  195.         value_ptr->refcount++;
  196.     } else {
  197.         if (variable_ptr->refcount>1) { /* we need to break away */
  198.             SEPARATE_ZVAL(variable_ptr_ptr);
  199.         }
  200.         (*variable_ptr_ptr)->is_ref = 1;
  201.     }
  202.  
  203.     if (result && !(result->u.EA.type & EXT_TYPE_UNUSED)) {
  204.         Ts[result->u.var].var.ptr_ptr = variable_ptr_ptr;
  205.         SELECTIVE_PZVAL_LOCK(*variable_ptr_ptr, result);
  206.         AI_USE_PTR(Ts[result->u.var].var);
  207.     }
  208. }
  209.  
  210. #define IS_OVERLOADED_OBJECT 1
  211. #define IS_STRING_OFFSET 2
  212.  
  213. #endif /* ZEND_EXECUTE_H */
  214.